/*
 * Copyright (C) 2025 Thomas Akehurst
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.tomakehurst.wiremock.db.mapper;

import com.github.tomakehurst.wiremock.db.entity.StubMappingEntity;

import java.time.LocalDateTime;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

@Mapper
public interface StubMappingMapper {

  int insert(StubMappingEntity entity);

  int update(StubMappingEntity entity);

  StubMappingEntity findById(@Param("id") String id);

  List<StubMappingEntity> findAll();
  // （可选）新增：按权限查询Stub（对应XML中的findByPermission）
  List<StubMappingEntity> findByPermission(@Param("permission") String permission);

  int deleteById(@Param("id") String id);

  int deleteAll();
  // 新增：根据 contentId 查询（关联 wm_multi_mapping 的 ID）
  List<StubMappingEntity> findByContentId(String contentId);

  /**
   * 条件分页查询单存根（与 XML 语句参数对应）
   * @param name 文件名（对应 originalFilename，模糊查询）
   * @param demandId 需求ID（模糊查询）
   * @param createUserId 创建人ID（精确查询）
   * @param updatedAt 更新时间（精确查询，可扩展为范围）
   * @param offset 分页偏移量（（pageNum-1）*pageSize）
   * @param pageSize 每页条数
   * @return 符合条件的单存根实体列表
   */
  List<StubMappingEntity> findByConditionsWithPage(
          @Param("name") String name,
          @Param("demandId") String demandId,
          @Param("createUserId") String createUserId,
          @Param("updatedAt") LocalDateTime updatedAt,
          @Param("offset") int offset,
          @Param("pageSize") int pageSize
  );
}
